//
//  WPRightManageTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/6.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPRightManageUsableCell.h"


@interface WPRightManageUsableCell ()
@property (nonatomic, strong) UIView * grayView;/**< 灰色背景图 */
@property (nonatomic, strong) UILabel * positionLabel;/**< 位置 */
@property (nonatomic, strong) UILabel * priceLabel;/**< 价格 */
@property (nonatomic, strong) UIImageView * rcodeImage;/**< 二维码图案 */
@property (nonatomic, strong) UIButton * editBtn;/**< 编辑按钮 */
- (void)initializeAppearance;/**< 一般界面初始化 */


@end
@implementation WPRightManageUsableCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    [self addSubview:self.grayView];
    [self addSubview:self.positionLabel];
    [self addSubview:self.priceLabel];
    [self addSubview:self.rcodeImage];
    [self addSubview:self.editBtn];
}
- (void)setModel:(WPRightManageDetailModel *)model {
    _model = model;
    _positionLabel.text = _model.ticketPosition;
    _priceLabel.text = [NSString stringWithFormat:@"%@", _model.price];
}
#pragma mark - responds events
- (void)respondsToEditBtn:(UIButton *)sender {
    if (_isDetail || [[UserModel defaultUser].memberRankNumber integerValue] == 1) {
        return;
    }
    sender.selected = !sender.selected;
    if (self.delegate && [_delegate respondsToSelector:@selector(actionOnEditBtnWithDetailModel:andWithIsAdd:)]) {
        [_delegate actionOnEditBtnWithDetailModel:_model andWithIsAdd:sender.selected];
    }
}
- (void)respondsToRcode {
//    [WPTicketRcodeAlertView showViewWithSize:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 90*DHFlexibleHorizontalMutiplier(), 270*DHFlexibleHorizontalMutiplier(), 450*DHFlexibleVerticalMutiplier()) andWithTitle:@"取票二维码" andWithDatasource:@[@"banner1", @"王者归来 Rain亚洲巡回演唱会", @"成都市体育馆", @"2016-04-26", @"取票时间：2016-04-23 9：00~ 18：00"] andWithComplete:^(NSString *result) {
//        
//    }];
}
#pragma mark - getter
- (UIView *)grayView {
    if (!_grayView) {
        _grayView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), 0, 290*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            view;
        });
    }
    return _grayView;
}
- (UILabel *)positionLabel {
    if (!_positionLabel) {
        _positionLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(15*DHFlexibleHorizontalMutiplier(), 0, 70*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab;
        });
    }
    return _positionLabel;
}
- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(85*DHFlexibleHorizontalMutiplier(), 0, 70*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab;

        });
    }
    return _priceLabel;
}
- (UIImageView *)rcodeImage {
    if (!_rcodeImage) {
        _rcodeImage = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(185*DHFlexibleHorizontalMutiplier(), 7*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            view.userInteractionEnabled = YES;
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToRcode)];
            [view addGestureRecognizer:tap];
            view.image = IMAGE_NAME(@"iconfont_erweima.png");
            view;
        });
    }
    return _rcodeImage;
}
- (UIButton *)editBtn {
    if (!_editBtn) {
        _editBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(250*DHFlexibleHorizontalMutiplier(), 6*DHFlexibleHorizontalMutiplier(), 18*DHFlexibleHorizontalMutiplier(), 18*DHFlexibleHorizontalMutiplier());
            [btn setImage:IMAGE_NAME(@"iconfont_hx.png") forState:UIControlStateSelected];
            [btn setImage:IMAGE_NAME(@"iconfont_wx.png") forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(respondsToEditBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _editBtn;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
